import os
import random
import shutil
import xml.etree.ElementTree as ET

from utils.utils import get_classes

VOCdevkit_path = 'voc1000'
ignore = ['car','chair']
if __name__ == "__main__":
    xmlfilepath = os.path.join(VOCdevkit_path, 'Annotations')
    xmlfiles = os.listdir(xmlfilepath)
    fileOutPath = os.path.join(VOCdevkit_path, 'Annotations_out')
    if not os.path.exists(fileOutPath):
        os.mkdir(fileOutPath)
    for index,fileName in enumerate(xmlfiles):
        tree = ET.ElementTree
        tree = ET.parse(os.path.join(xmlfilepath, fileName))
        root = tree.getroot()

        # if index%4 == 0: 
        #     needmove = True
        # else:
        #     continue
        needmove = True
        for obj in root.findall('object'):
            objName = obj.find('name')
            if objName.text in ignore:
                needmove = False
                break
        if needmove:
            shutil.move(os.path.join(xmlfilepath,fileName),os.path.join(fileOutPath,fileName))
            print(fileName)
